package py.una.pol.tesis.ii.emergenciasmovil.app.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.SearchView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import java.util.ArrayList;

import py.una.pol.tesis.ii.emergenciasmovil.app.R;
import py.una.pol.tesis.ii.emergenciasmovil.app.adapter.HistorialListAdapter;

/**
 * Created by Leandro on 13/09/2014.
 */
public class HistorialFragment extends Fragment implements SearchView.OnQueryTextListener{

    private ListView listViewHist ;
    private HistorialListAdapter histListAdapter;
    private int posicion;

    private final int MENU_NUEVA_NOTI = 1;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View v = inflater.inflate(R.layout.fragment_historial, container, false);


        listViewHist = (ListView) v.findViewById(R.id.historial_list);

        histListAdapter = new HistorialListAdapter(this.getActivity());

        // Assign adapter to ListView
        listViewHist.setAdapter(histListAdapter);
        setHasOptionsMenu(true);
        return v;

    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.menu_search, menu);
        super.onCreateOptionsMenu(menu, inflater);

        MenuItem searchItem = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);


        searchView.setOnQueryTextListener(this);
    }


    @Override
    public boolean onQueryTextSubmit(String s) {
        return false;
    }

    @Override
    public boolean onQueryTextChange(String newText) {
        if (TextUtils.isEmpty(newText)) {
            histListAdapter.filtrar("");
            listViewHist.clearTextFilter();
        } else {
            histListAdapter.filtrar(newText.toString());
        }
        return true;
    }
}
